clear

do "ic2009.do"

clear
use "dct_ef2009a.dta"

*Get the grand total first-time undergraduate students
 keep if efalevel==4 & line==99 & section==3 & lstudy==1
 keep unitid eftotlt
 save "ef2009a_firsttimestud.dta", replace


clear
use "degenrollempstaff_inst_8018.dta"

keep if year==2009
merge 1:1 unitid using "ic2009.dta"
rename _merge mergeadmitfull
drop if mergeadmitfull==2

merge 1:1 unitid using "ef2009a_firsttimestud.dta"
rename _merge mergeenroll
keep if mergeenroll==3

gen fracadmit = admssn/applcn

gen openadmit = openadmp==1
replace openadmit=. if openadmp==-2

gen rec = admcon5==1|admcon5==2
replace rec = . if admcon5==-2

gen test = admcon7==1|admcon7==2
replace test = . if admcon7==-2

preserve
keep if four_yr==1
collapse public openadmit fracadmit rec test satvr25 satvr75 satmt25 satmt75 actcm25 actcm75 [aw=eftotlt], by(cty_fips)

merge 1:1 cty_fips using "justnormasylum.dta"
rename _merge mergenorm
keep if mergenorm==3

tostring cty_fips, gen(cty_fipstr)
gen statefip = substr(cty_fipstr, 1,1) if length(cty_fipstr)==4
replace statefip = substr(cty_fipstr, 1, 2) if length(cty_fipstr)==5
destring statefip, replace

local vars  public openadmit fracadmit rec test satvr25 satvr75 satmt25 satmt75 actcm25 actcm75
foreach x of local vars{
reghdfe `x' hasnormalschool, absorb(statefip) cluster(statefip)
outreg2 using instchars.xls, excel append dec(3)

#delimit ;
tabout hasnormalschool if hasnormalorasylum==1 & e(sample)==1 using sumstats_instchars.xls,
append c(mean `x' sd `x') npos(row) f(2)  layout(row) sum show(none); 
#delimit cr
} 

